<template>
	<view>
		<view class="nav">
			<u-tabs :current="check - 1" :itemStyle="{ width:'50%',height:'80rpx'}"
				:activeStyle="{ color: '#E84E22' , fontSize:'32rpx' }" lineColor='#E84E22'
				:inactiveStyle="{ color: '#666666',fontSize: '28rpx' }" :list="list1" @click="click"></u-tabs>
		</view>
		<view v-if="showBox">
			<view class="inpu">
				<view class="table">
					申请数量
				</view>
				<view class="inputBox">
					<image class="imp" src="@/static/images/work/imp.png"></image>
					<u--input placeholder="请输入内容" border="surround" v-model="dataForm.applyNum" type="number"
						v-if="inputShow" />
					<view class="impTxt" v-else @click="inputShow=true">
						请输入
					</view>
				</view>
			</view>
			<view class="noBorder">
				<view class="table">
					申请原因
				</view>
				<view class="textBox">
					<u--textarea v-model="dataForm.reason" placeholder="请输入内容" />
				</view>
			</view>
			<view class="addres" @click="toAddress">
				<view class="addresTitle">
					<view class="resTL">
						收货地址
					</view>
					<view class="resTR">
						<view class="TrT">
							管理
						</view>
						<image class="TrTImg" src="../../static/images/minde/arrow.png"></image>
					</view>
				</view>
				<view class="addresCont" v-if="address.name">
					<view class="addresIcon">
						<image class="contIcon" src="../../static/images/work/address.png"></image>
					</view>
					<view class="contInfoBox">
						<view class="infoTop">
							<text>{{address.name}}</text><text style="margin-left: 20rpx;">{{address.mobile}}</text>
						</view>
						<view class="infoBom">
							地址:{{address.areaName}} {{address.detailAddress}}
						</view>
					</view>
				</view>
				<view v-else>
					请选择地址
				</view>
			</view>
			<view class="sbuit" @click="toApply">
				提交
			</view>
			<view class="exBox" @click="toNotes">
				<view class="hen">

				</view>
				<view class="henTxt">
					查看历史申请记录
				</view>
				<view class="hen">

				</view>
			</view>
		</view>
		<view v-else>
			<view class="noBorder2">
				<view class="table2">
					请选择补牌的桌号
				</view>
			</view>
			<view class="bigBox">
				<u-checkbox-group :value="checked" iconPlacement="left" placement="row" @change="checkboxChange">
					<u-checkbox :customStyle="{marginBottom: '20rpx',width:'130rpx',marginLeft:'10rpx'}"
						v-for="item in checkboxList1" :key="item.id" :label="item.deskNum" :name="item.deskNum"
						shape="circle" activeColor="#ff592b" />
				</u-checkbox-group>
			</view>
			<view class="noBorder">
				<view class="table">
					申请原因
				</view>
				<view class="textBox">
					<u--textarea v-model="dataForm.reason" placeholder="请输入内容" />
				</view>
			</view>
			<view class="addres" @click="toAddress">
				<view class="addresTitle">
					<view class="resTL">
						收货地址
					</view>
					<view class="resTR">
						<view class="TrT">
							管理
						</view>
						<image class="TrTImg" src="../../static/images/minde/arrow.png"></image>
					</view>
				</view>
				<view class="addresCont" v-if="address.name">
					<view class="addresIcon">
						<image class="contIcon" src="../../static/images/work/address.png"></image>
					</view>
					<view class="contInfoBox">
						<view class="infoTop">
							<text>{{address.name}}</text><text style="margin-left: 20rpx;">{{address.mobile}}</text>
						</view>
						<view class="infoBom">
							地址:{{address.areaName}} {{address.detailAddress}}
						</view>
					</view>
				</view>
				<view v-else>
					请选择地址
				</view>
			</view>
			<view class="sbuit" @click="toApply">
				提交
			</view>
			<view class="exBox" @click="toNotes">
				<view class="hen">

				</view>
				<view class="henTxt">
					查看历史申请记录
				</view>
				<view class="hen">

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyDeskList,
		createDeskApply
	} from "@/api/desk/desk.js"
	import {
		getAddress
	} from "@/api/wine/wine.js"
	export default {
		data() {
			return {
				list1: [{
					name: '申请桌牌',
					type: 1
				}, {
					name: '申请补牌',
					type: 2
				}],
				dataForm: {
					type: undefined,
					deskIds: undefined,
					applyNum: undefined,
					addressId: undefined,
					reason: undefined,
				},
				check: 1,
				inputShow: false,
				showBox: true, //展示那个盒子
				checked: [], //选中的桌牌数组
				checkboxList1: [],
				address:{},
			}
		},
		onLoad() {
			this.getAddress()
			this.dataForm.type = 0
		},
		methods: {
			//获得默认地址
			getAddress(){
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				//TODO 客户id是写死的
				getAddress().then(response => {
					uni.hideLoading()
					if (response.code == 0) {
						that.address = response.data
					}
				})
			},
			//收货地址
			toAddress() {
				this.$tab.navigateTo('/pagesA/address/address?type=' + 1)
			},
			checkboxChange(n) {
				// console.log(n)
				this.checked = n
			},
			//获取补牌记录
			getMyDesk() {
				let that = this
				that.checked = []
				getMyDeskList().then(res2 => {
					if (res2.code == 0) {
						that.checkboxList1 = res2.data
					}
				})
			},
			//申请桌牌
			async toApply() {
				this.dataForm.addressId = this.address.id
				this.dataForm.deskIds = this.checked
				await createDeskApply(this.dataForm);
				uni.showToast({
					title: '申请成功',
					duration: 2000
				});
				this.$tab.navigateTo('/pagesA/tableNotes/tableNotes')
			},
			//跳转申请记录
			toNotes() {
				this.$tab.navigateTo('/pagesA/tableNotes/tableNotes')
			},
			//导航点击
			click(item) {
				this.dataForm = {};
				if (item.type === 1) {
					this.showBox = true
					this.dataForm.type = 0;
				} else if (item.type === 2) {
					this.dataForm.type = 1
					this.showBox = false
					this.getMyDesk()
				}
			}
		},
	}
</script>

<style>
	page {
		background-color: white;
	}

	.nav {
		width: 750rpx;
		height: 100rpx;
		background-color: #F5F5F5;
		position: fixed;
		top: 0;
		z-index: 1;
	}

	.inpu {
		width: 690rpx;
		height: 100rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 100rpx auto 0 auto;
		/* background-color: red; */
		border-bottom: 2rpx solid #F1F1F1;
		;
	}

	.table {
		width: 150rpx;
		height: 100rpx;
		font-size: 28rpx;
		line-height: 100rpx;
		color: #404040;
	}

	.inputBox {
		width: 150rpx;
		height: 100rpx;
		display: flex;
		align-items: center;
	}

	.imp {
		width: 20rpx;
		height: 20rpx;
	}

	.impTxt {
		width: 100rpx;
		height: 100rpx;
		line-height: 100rpx;
		margin-left: 10rpx;
		font-size: 28rpx;
		color: #999999;
	}

	.noBorder {
		width: 690rpx;
		height: 100rpx;
		margin: 0 auto;
	}

	.textBox {
		width: 690rpx;
		height: 272rpx;
	}

	.sbuit {
		width: 690rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		background: #E84E22;
		border-radius: 50rpx;
		margin: 100rpx auto 0 auto;
		font-size: 32rpx;
		color: #FFFFFF;
	}

	.exBox {
		width: 750rpx;
		height: 50rpx;
		line-height: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 60rpx;
	}

	.hen {
		width: 26rpx;
		height: 2rpx;
		background-color: #999999;
	}

	.henTxt {
		width: 220rpx;
		height: 50rpx;
		text-align: center;
		font-size: 24rpx;
		color: #999999;
	}

	/* 补牌 */
	.noBorder2 {
		width: 690rpx;
		height: 100rpx;
		margin: 100rpx auto 0 auto;
	}

	.table2 {
		width: 500rpx;
		height: 100rpx;
		font-size: 28rpx;
		line-height: 100rpx;
		color: #404040;
	}

	.bigBox {
		width: 690rpx;
		margin: 0 auto;
		padding-bottom: 10rpx;
		border-bottom: 2rpx solid #F1F1F1;
		/* background-color: red; */
	}

	/* 地址 */
	.addres {
		width: 690rpx;
		height: 230rpx;
		border-top: 2rpx solid #F1F1F1;
		border-bottom: 2rpx solid #F1F1F1;
		margin: 200rpx auto 0 auto;

	}

	.addresTitle {
		width: 690rpx;
		height: 100rpx;
		line-height: 100rpx;
		display: flex;
		justify-content: space-between;
	}

	.resTL {
		width: 150rpx;
		height: 100rpx;
		font-size: 28rpx;
		color: #333333;
	}

	.resTR {
		width: 100rpx;
		height: 100rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 28rpx;
		color: #999999;
	}

	.TrTImg {
		width: 15rpx;
		height: 25rpx;
		margin-left: 20rpx;
	}

	.addresCont {
		width: 690rpx;
		height: 200rpx;
		display: flex;
		justify-content: space-between;
	}

	.addresIcon {
		width: 50rpx;
		height: 200rpx;
		display: block;
		margin-top: 10rpx;
	}

	.contIcon {
		width: 30rpx;
		height: 30rpx;
	}

	.contInfoBox {
		width: 630rpx;
		height: 100rpx;
		line-height: 50rpx;
		font-weight: bold;
		font-size: 28rpx;
		color: #333333;
	}

	.infoTop {
		width: 600rpx;
		height: 50rpx;
	}

	.infoBom {
		width: 600rpx;
		height: 50rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		-o-text-overflow: ellipsis;
	}
</style>